require("../util.js");
require("../component/components.js");
// require("../component/friendHeader.js");
// require("../component/footer.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
if(!userInfo){
    location.href="/loginIndex"
}
var vm = new Vue({
    el:"#circleSquare",
    data:{
        loginUid:userInfo.id,
        category:{},
        categoryId:"",
        categoryList:{}
    },
    mounted:function(){
        this.circleCategory();
    },
    methods:{
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        //后退
        getBack:function(){
            location.href="/friend?indexs=3";
            // history.go(-1);
        },
        //乐友-圈子广场-圈子分类列表
        circleCategory:function(){
            var that=this;
            this.ajax({url:"/friend/circleCategory",dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.category=b.json.data;
                    that.circleCategoryList(that.category[0].categoryId);
                    console.log(that.category)
                }else{
                    vm.$refs.prompt.toast("获取分类失败！")
                }
            });
        },
        //乐友-圈子广场-分类圈子列表
        circleCategoryList:function(id){
            var that=this;
            if(id){that.categoryId=id;}
            that.categoryList={};
            var data={
                loginUid:that.loginUid,
                categoryId:that.categoryId
            };
            this.ajax({url:"/friend/circleCategoryList",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.categoryList=b.json.data;
                    console.log(that.categoryList)
                }else{
                    vm.$refs.prompt.toast("获取分类圈子列表失败！")
                }
            });
        },
        //通过用户id 加入圈子
        joinGroup:function(id){
            var that=this;
            var data={
                loginUid:that.loginUid,
                circleId:id
            };
            this.ajax({url:"/friend/joinGroup",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    vm.$refs.prompt.toast(b.json.data);
                    that.circleCategoryList();
                }else{
                    vm.$refs.prompt.toast("加入圈子失败！")
                }
            });
        },
        //跳转页面
        getNext:function(ucId,circleId){
            if(ucId==1){
                location.href="/friend/circleBar?type=2&square=1&circleId="+circleId+"&uid="+this.loginUid;
            }else if(ucId==0){
                this.joinGroup(circleId)
            }
        }
    }
});